package com.baozhun.mall.common.network

import com.baozhun.mall.common.model.HomePageBean
import com.baozhun.mall.common.model.bean.*
import com.baozhun.mall.common.model.request.AppUpdateReqBean
import com.baozhun.mall.common.model.request.UpdateUserInfoReqBean
import com.baozhun.mall.common.util.CacheUtil
import okhttp3.MultipartBody
import retrofit2.http.*

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2023/2/11
 * @Version：1.0.0
 */
interface CommonApiService {


    /**
     * 获取个人信息数据
     */
    @FormUrlEncoded
    @POST("user/user-info")
    suspend fun getUserInfo(@Field("Authorization") authorization: String = CacheUtil.getUser().token): ApiResponse<UserInfo>

    /**
     * 获取当前用户未读信息总数
     */
    @GET("sys-msg/count")
    suspend fun getMsgCount(): ApiResponse<Int?>

    /**
     * 消息已读
     */
    @GET("sys-msg/read")
    suspend fun readMsg(): ApiResponse<Any?>

    /**
     * 获取app更新信息
     */
    @POST("upgrade/index")
    suspend fun getAppUpdateInfo(@Body appUpdateReqBean: AppUpdateReqBean): ApiResponse<AppUpdateBean>

    /**
     * 更新个人信息数据
     */
    @POST("user/user-update")
    suspend fun updateUserInfo(@Body updateUserInfoReqBean: UpdateUserInfoReqBean?): ApiResponse<Any?>


    @GET("goods/get-all-category")
    suspend fun getCategoryList(): ApiResponse<MutableList<ClassifyInfo>>


    /**
     * 上传图片
     */
    @Multipart
    @POST("upload/img-upload")
    suspend fun uploadPic(@Part part: List<MultipartBody.Part>): ApiResponse<UploadResultBean>

    /**
     *
     * 取消收藏
     */
    @GET("user/delete_favorite")
    suspend fun cancelCollection(
        @Query("goods_ids") goods_ids: String,
        @Query("goods_type") goodsType: String?
    ): ApiResponse<Any?>

    /**
     * 加入购物车
     */
    @FormUrlEncoded
    @POST("cart/add")
    suspend fun addCart(
        @Field("goods_id") goods_id: String,
        @Field("sku_id") sku_id: String,
        @Field("num") num: String,
        @Field("seckill_id") seckillId: String?
    ): ApiResponse<Any?>


    /**
     * 添加收藏
     */
    @GET("user/goods_favorite")
    suspend fun addCollect(
        @Query("goods_id") goods_id: String,
        @Query("goods_type") goodsType: String?
    ): ApiResponse<Any>



    /**
     * 发送邮箱验证码
     */
    @POST("login/send-mail-code")
    suspend fun sendEmailVerifyCode(
        @Body params: ResetPwdReqBean
    ): ApiResponse<UserInfo?>

    /**
     * 一键登陆
     */
    @FormUrlEncoded
    @POST("auth/mobile-click-login")
    suspend fun oneKeyLogin(
        @Field("code") token: String?,
        @Field("invite_code") inviteCode: String?
    ): ApiResponse<UserInfo?>

    /**
     *SKU级别商品购买时点数数据动态计算
     */
    @FormUrlEncoded
    @POST("goods/getDynamicIntegralBySku")
    suspend fun getGoodsPointInfo(
        @Field("sku_id") skuId: String?,
        @Field("buy_num") buyNum: Int?,
    ): ApiResponse<GoodsInfoBean>

    /**
     * 获取app配置接口
     */
    @GET("config/get")
    suspend fun getAppConfig(): ApiResponse<AppConfigBean>


    /**
     * 首页列表数据
     */
    @GET("index/data")
    suspend fun getHomeData(): ApiResponse<HomePageBean>


    /**
     * 获取验证码
     */
    @FormUrlEncoded
    @POST("account/send-sms")
    suspend fun getVerifyCode(
        @Field("phone") phone: String?,
        @Field("imei") imei: String?,
        @Field("os") os: String = "android",
    ): ApiResponse<Any?>


}

val mCommonApiService: CommonApiService by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
    NetworkApi.INSTANCE.getApi(CommonApiService::class.java, NetworkApi.Companion.SERVER_URL)
}